var tabsMenu; //tab右击菜单

$(function() {
//	鼠标右击tab初始化
	tabsMenu = $('#tabsMenu').menu({
		onClick : function(item) {
			var curTabTitle = $(this).data('tabTitle');
			var type = $(item.target).attr('type');

			if (type === 'refresh') {
				refreshTab(curTabTitle);
				return;
			}

			if (type === 'close') {
				var t = menutab.tabs('getTab', curTabTitle);
				if (t.panel('options').closable) {
					menutab.tabs('close', curTabTitle);
				}
				return;
			}

			var allTabs = menutab.tabs('tabs');
			var closeTabsTitle = [];

			$.each(allTabs, function() {
				var opt = $(this).panel('options');
				if (opt.closable && opt.title != curTabTitle && type === 'closeOther') {
					closeTabsTitle.push(opt.title);
				} else if (opt.closable && type === 'closeAll') {
					closeTabsTitle.push(opt.title);
				}
			});

			for ( var i = 0; i < closeTabsTitle.length; i++) {
				menutab.tabs('close', closeTabsTitle[i]);
			}
		}
	});

	menutab = $('#menutab').tabs({
		fit : true,
		border : false,
		onContextMenu : function(e, title) {
			e.preventDefault();
			tabsMenu.menu('show', {
				left : e.pageX,
				top : e.pageY
			}).data('tabTitle', title);
		}
	});


});
function refreshTab(title) {
	var tab = menutab.tabs('getTab', title);
	menutab.tabs('update', {
		tab : tab,
		options : tab.panel('options')
	});
}
createTabs = function(url, name, cssid) {
	
	var obj = new Object();
	obj.url = url;
	obj.text = name;
	addTab(obj);
	changeLeftCss(cssid);
}


changeLeftCss = function(cssid) {
	if ($('.easyui-accordion div[class^="active"]') != null) {
		$('.active').removeClass('active');
		$('.neuactive').removeClass('neuactive');
	}

	$("#" + cssid).parent().addClass('active');
	$("#" + cssid).addClass('neuactive');
}

/**
 * 登陆权限 WangPeixi
 */
$(function() {
	var userName = postAsyncAjax("/findUserName").name;
	$("#userName").text(userName);
	var id = "limits";
	var title = "";
	var contect = "";
	var dataLimit = postAsyncAjax("/findLimitsByUserId");
	var data = dataLimit.data;
	if (dataLimit.warning!='1') {
		$("#warning").attr("hidden","true");
		$("#lingdang").removeAttr("autoplay");
		top.$("#lingdang").removeAttr("loop");
	}
	if (data == undefined)
		window.top.location.href = "/index.html";
	// 遍历菜单
	var sum = 0;
	for (var i = 0; i < data.length; i++) {
		if (data[i].parentCode == 0) {
			title = data[i].name;
			for (var j = 0; j < data.length; j++) {
				if (data[j].parentCode == data[i].code) {
					var parentCode = data[j].code;
					var url = data[j].addr;
					var name = data[j].name;
					var icon = data[j].icon;
					var ids = data[j].id;
					contect += "<div  onclick =\"createTabs('"
							+ url
							+ "?parentCode="
							+ parentCode
							+ "','"
							+ name
							+ "','menu"
							+ (ids)
							+ "')\"><a  href=\"#\" id=\"menu"
							+ (ids)
							+ "\" class=\"easyui-linkbutton btncss\" ondragstart=\"return false\" data-options=\"iconCls:'"
							+ icon + "'\">" + name + "</a></div>";

				}
			}
			sum++;
			addAccordion(id, title, contect, data[i].icon, sum);
		}
		contect = "";
	}
});

// 退出登录
function signout() {
	parent.$.messager.confirm('确认对话框', '确认退出登录？', function(r) {
		if (r) {
			var data = postAsyncAjax("/exitLogin", null);
			if (data.returnCode == "00") {
				window.top.location.href = "/index.html";
			}
		}
	});
}
// 修改密码
changePwd = function() {
	topWindow("/view/page/user/updatePwd.html", "修改密码", {
		width : 610,
		height : 300
	});
}

